Public Class UpdateStatement
    Public WhereClause As WhereClause
    Public AssignList As New Generic.List(Of AssignmentExpression)

    Public TableName As String

    Public Sub New(ByVal nodes As Parser.SyntaxNode)
        Parse(nodes, String.Empty)
    End Sub

    Private Sub Parse(ByVal noder As Parser.SyntaxNode, ByVal ruleName As String)
        Debug.Assert(noder IsNot Nothing)
        Debug.Assert(noder.GetType.ToString = GetType(Parser.NonTerminalNode).ToString)
        Dim root As Parser.NonTerminalNode = CType(noder, Parser.NonTerminalNode)

        For idx As Integer = 0 To root.Count - 1
            Dim node As Parser.SyntaxNode = root.Item(idx)
            Select Case node.GetType().ToString
                Case GetType(Parser.NonTerminalNode).ToString
                    Dim n As Parser.NonTerminalNode = node
                    Select Case n.RuleName.ToUpper()
                        Case "<ASSIGN LIST>"
                            Me.AssignList.Add(ParseAssignList(n, n.RuleName, Nothing))
                        Case "<WHERE CLAUSE>"
                            ParseWhereClause(n, n.RuleName, Nothing)
                        Case "<TABLE NAME>"
                            Parse(n, n.RuleName)
                    End Select
                Case GetType(Parser.TerminalNode).ToString
                    Dim t As Parser.TerminalNode = CType(node, Parser.TerminalNode)
                    Select Case ruleName.ToUpper
                        Case "<TABLE NAME>"
                            Me.TableName = t.Text
                    End Select
            End Select
        Next
    End Sub

    Private Function ParseAssignList(ByVal noder As Parser.SyntaxNode, ByVal ruleName As String, ByVal exp As AssignmentExpression) As AssignmentExpression
        Debug.Assert(noder IsNot Nothing)
        Debug.Assert(noder.GetType.ToString = GetType(Parser.NonTerminalNode).ToString)
        Dim root As Parser.NonTerminalNode = CType(noder, Parser.NonTerminalNode)
        If exp Is Nothing Then exp = New AssignmentExpression
        For idx As Integer = 0 To root.Count - 1
            Dim node As Parser.SyntaxNode = root.Item(idx)
            Select Case node.GetType().ToString
                Case GetType(Parser.NonTerminalNode).ToString
                    Dim n As Parser.NonTerminalNode = node
                    exp = ParseAssignList(n, n.RuleName, exp)
                Case GetType(Parser.TerminalNode).ToString
                    Dim t As Parser.TerminalNode = CType(node, Parser.TerminalNode)

                    Select Case ruleName.ToUpper
                        Case "<FIELD NAME>"
                            exp.Left = t.Text
                        Case "<VALUE>"
                            exp.Right = t.Text
                        Case "<PARAMETER NAME>"
                            exp.Right = "@" & t.Text
                    End Select
            End Select
        Next
        Return exp
    End Function
    Private Sub ParseWhereClause(ByVal node As Parser.SyntaxNode, ByVal ruleName As String, ByVal level As Integer)

    End Sub
End Class

Public Class AssignmentExpression
    Public Left As String
    Public Right As String
    Public Sub New()

    End Sub
    Public Sub New(ByVal left As String, ByVal right As String)
        Me.Left = left
        Me.Right = right
    End Sub

End Class
